﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;
using System.Data;
namespace DAO
{
    public class BIENNHANVIENDAO
    {
        public void thembien(BOPHANDTO bpDTO)
        {
            SqlConnection conn = DATAPROVIDER.ConnectSQL();
            string sql1 = "INSERT INTO BIEN_NHAN_VIEN(BoPhan,GiaTri) VALUES (@bp,@gt)";
            SqlCommand cmd = new SqlCommand(sql1, conn);

            SqlParameter sqlparameter = new SqlParameter("@bp", System.Data.SqlDbType.NVarChar, 50);
            sqlparameter.Value = bpDTO.Mabophan;
            cmd.Parameters.Add(sqlparameter);

            sqlparameter = new SqlParameter("@gt", System.Data.SqlDbType.Int);
            sqlparameter.Value = 0;
            cmd.Parameters.Add(sqlparameter);

            cmd.ExecuteNonQuery();
            conn.Close();
            conn.Dispose();
        }
        public void updatebiennhanvien(NHANVIENDTO nvDTO)
        {
            SqlConnection conn = DATAPROVIDER.ConnectSQL();
            string sql1 = "SELECT GiaTri FROM BIEN_NHAN_VIEN WHERE BoPhan='" + nvDTO.Mabophan + "'";
            SqlCommand cmd = new SqlCommand(sql1, conn);
            object temp = cmd.ExecuteScalar();
            int temp1 = Convert.ToInt32(temp);
            temp1++;
            string sql = "UPDATE BIEN_NHAN_VIEN SET GiaTri= " + temp1 + " WHERE BoPhan='" + nvDTO.Mabophan + "'";
            cmd = new SqlCommand(sql, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
            conn.Dispose();
        }
    }
}
